package com.hook3.pianke.Adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hook3.pianke.R;
import com.hook3.pianke.domain.PrivateRadioInfo;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by HOME on 2015/12/10.
 */
public class PrivateRadioListBaseAdapter extends BaseAdapter {
    private ArrayList<PrivateRadioInfo.PrivateRadioEachContent> privateRadiolist;
    private Activity activity;

    public PrivateRadioListBaseAdapter(Activity activity,ArrayList<PrivateRadioInfo.PrivateRadioEachContent> privateRadiolist){
        this.privateRadiolist = privateRadiolist;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return privateRadiolist.size();
    }

    @Override
    public PrivateRadioInfo.PrivateRadioEachContent getItem(int position) {
        return privateRadiolist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(activity, R.layout.item_private_radio_list,null);
            holder.radioIcon = (ImageView) convertView.findViewById(R.id.iv_private_radio_list_icon);
            holder.isNew = (ImageView) convertView.findViewById(R.id.iv_private_radio_list_new);
            holder.radioName = (TextView) convertView.findViewById(R.id.tv_private_radio_list_radio_name);
            holder.receivers = (TextView) convertView.findViewById(R.id.tv_private_radio_list_radio_receivers);
            holder.play = (ImageView) convertView.findViewById(R.id.iv_private_radio_list_radio_play);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        PrivateRadioInfo.PrivateRadioEachContent item = getItem(position);

        //设置图片
        //设置广播图片
        ImageOptions imageOptions = new ImageOptions.Builder().build();
        x.image().bind(holder.radioIcon, item.coverimg, imageOptions);

        //设置new图片
        if(item.isnew){
            holder.isNew.setVisibility(View.VISIBLE);
        }else{
            holder.isNew.setVisibility(View.INVISIBLE);
        }

        holder.radioName.setText(item.title);

        holder.receivers.setText(item.musicVisit);

        return convertView ;
    }

    static class ViewHolder{
        ImageView radioIcon;
        ImageView isNew;
        TextView radioName;
        TextView receivers;
        ImageView play;
    }

}
